<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const p1 = Promise.resolve('p1 resolve')

        const p2 = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('p2 延迟2s')
            }, 2000)
        })

        const p3 = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('p3 延迟3s')
            }, 3000)
        })

        const p4 = Promise.reject('p4 reject')

        const p5 = new Promise((resolve, reject) => {
            setTimeout(() => {
                reject('p5 延迟 1s')
            }, 1000)
        })

        //race 谁快听谁的
        /*  Promise.race([p1, p2, p3])
             .then(res => { console.log(res) })
             .catch(err => { console.log(err) })
         Promise.race([p3, p2, p4])
             .then(res => { console.log(res) })
             .catch(err => { console.log(err) }) */

        //any 首个成功即成功
        /* Promise.any([p1, p4, p5])
            .then(res => { console.log(res) })
            .catch(err => { console.log(err) })
        Promise.any([p4, p5])
            .then(res => { console.log(res) })
            .catch(err => { console.log(err) }) */

        //allSettled 全部完成才结束
        Promise.allSettled([p1, p4, p5])
            .then(res => { console.log(res) })
            .catch(err => { console.log(err) })
        Promise.allSettled([p4, p5])
            .then(res => { console.log(res) })
            .catch(err => { console.log(err) })


    </script>
</body>

</html>